package cn.dkk.create_design.builder.ConsturctorBuilder;

/**
 * @author dkk
 * @date 2022/7/10
 * @desc 构造器构建者
 */
public class Phone {

    private String memory;

    private String cpu;

    private String screen;

    private String mainBoard;

    /**
     * 私有构造方法
     */
    private Phone(){
    }

    private Phone(Builder builder){
        memory=builder.memory;
        cpu=builder.cpu;
        screen=builder.screen;
        mainBoard=builder.mainBoard;
    }

    /**
     * 思想:
     * 1.先将属性值通过builder中属性的同名方法,给builder的同名属性赋值
     * 2.在赋值过程中返回值为this,保证链式编程
     * 3.在实体内中私有化构造方法,并提供一个传入builder的构造方法
     * 4.在该构造中,将builder的同名属性赋值给实体类
     * 5.在builder创建build方法,调用实体类的builder的构造方法(内部类可以直接访问外部类的私有方法)
     * 6.返回实例化的对象
     */
    static final class Builder{

        private String memory;

        private String cpu;

        private String screen;

        private String mainBoard;

        public Builder memory(String memory){
            this.memory=memory;
            return this;
        }

        public Builder cpu(String cpu){
            this.cpu=cpu;
            return this;
        }

        public Builder screen(String screen){
            this.screen=screen;
            return this;
        }

        public Builder mainBoard(String mainBoard){
            this.mainBoard=mainBoard;
            return this;
        }

        public Phone build(){
            return new Phone(this);
        }
    }

    @Override
    public String toString() {
        return "Phone{" +
                "memory='" + memory + '\'' +
                ", cpu='" + cpu + '\'' +
                ", screen='" + screen + '\'' +
                ", mainBoard='" + mainBoard + '\'' +
                '}';
    }

    public String getMemory() {
        return memory;
    }

    public void setMemory(String memory) {
        this.memory = memory;
    }

    public String getCpu() {
        return cpu;
    }

    public void setCpu(String cpu) {
        this.cpu = cpu;
    }

    public String getScreen() {
        return screen;
    }

    public void setScreen(String screen) {
        this.screen = screen;
    }

    public String getMainBoard() {
        return mainBoard;
    }

    public void setMainBoard(String mainBoard) {
        this.mainBoard = mainBoard;
    }
}
